<?php
class FenleiController extends Controller {
	private $data;
	private $dbs;
	private $path;
	public function __construct() {
		$this -> data =	include './data.php';
		$this->dbs = include './logindata.php';
		$this->path = './logindata.php';
	}

	public function index() {
		include './tpl/index.html';
	}
	public function bigsort(){
		$bid = $_GET['bid'];
//		$cid = $_GET['cid']?$_GET['cid']:$key;
		
//		$id = $_GET['id'];
		include './tpl/bigsort.html';
//		$cid = $key;
	}
	public function lists(){
		$bid = $_GET['bid'];
		$cid = $_GET['cid'];
//		$id = $_GET['id'];
		include './tpl/lists.html';
	}
	public function article(){
		$bid = $_GET['bid'];
		$cid = $_GET['cid'];
		$id = $_GET['id'];

		include './tpl/article.html';
	}
	public function post() {

		$cid = "便民,家政中心,搬家开锁,电脑家电维修,水暖电维修,送水送气,租车,快递,打字复印,运输物流,干洗擦鞋|摄影,婚纱摄影,儿童摄影|学校,补习班,培训机构,幼儿园,音乐舞蹈|餐饮,特色餐饮,绿色农家,烧烤店,火锅店,饭店,餐馆,西餐厅,快餐店,小吃|服饰,品牌店,服装店,内衣店,童装店,饰品店,鞋帽箱包|家装,五金建材,家具店,灯饰店,家居饰品,装潢材料|住宿,宾馆,招待所,客房|娱乐,旅游,网吧,酒吧,足浴水疗,瑜伽馆,KTV,养生馆,桌球城,健身房|百货,眼镜店,花店水族,化妆品,精品店,烟/酒/茶,超市,生活日杂,母婴用品,玩具店,文体用品,书店音像,乐器工艺品,佛教用品,百货,眼镜店,花店水族,化妆品,精品店,烟/酒/茶,超市,生活日杂,母婴用品,玩具店,文体用品,书店音像,乐器工艺品,佛教用品|家电,手机通讯,电脑数码,家电商场,维修|美容美发,美容院,美发美甲,减肥中心,SPA馆|汽车,机动车,非机动车,修配厂,轮胎店,汽车美容|医保,医院,诊所,药店,保健品,医疗器械|其它,广告制作,矿山设备,设备租用,畜牧养殖,其它";
		$col = explode('|', $cid);
//		echo count($col);  //打印栏目length
		// 用|截取后的13个栏目和字栏目 生成函数
//		var_dump($col);
//		$smallcol0 = explode(',', $col[0]);
		//通过截取，号来生成分开字符串
//		var_dump($smallcol0[0]);
		//通过调用指定下标访问指定内容
//		echo key($col);



	if (IS_POST) {
		for ($i = 0; $i < count($col); $i++) {
			//			栏目字符串分解
			$smallcol_[$i] = explode(',', $col[$i]);
//			var_dump($i . '==>' . $smallcol_[$i][$i]); 
//			var_dump( $smallcol_[$i]);
//			echo ($smallcol_[$i][0]);  //打印二级栏目length
//			echo count($smallcol_[$i]).'<br />';  //打印顶级栏目下每个栏目的length
				if ($_POST['{formName1}'] == $smallcol_[$i][0]) {
					$fistcol=$i; //保存栏目序列号
//					echo '栏目:'.$smallcol_[$i][0];  //打印发布栏目
					for ($si = 0; $si < count($smallcol_[$i]); $si++) {
						if ($_POST['{formName2}'] == $smallcol_[$i][$si]) {
							$secondcol=$si;  //保存耳机栏目序列号
//							echo '二级栏目:'.$smallcol_[$i][$si]; //输出发布的二级栏目名
						}
					}
				}
				
			
				}
//		判断栏目名和分类名 发布到对应序列号里
		if ($_POST['{formName1}'] == $smallcol_[$fistcol][0]) {
				if ($_POST['{formName2}'] == $smallcol_[$fistcol][$secondcol]) {
						$_POST['tit'] =empty($_POST['tit'])? '未填写':$_POST['tit'];
						$_POST['{formName1}'] =empty($_POST['{formName1}'])? '未填写':$_POST['{formName1}'];
						$_POST['qq'] =empty($_POST['qq'])? '未填写':$_POST['qq'];
						$_POST['{formName2}'] =empty($_POST['{formName2}'])? '未填写':$_POST['{formName2}'];
						$_POST['address'] =empty($_POST['address'])? '未填写':$_POST['address'];
						$_POST['linkman'] =empty($_POST['linkman'])? '未填写':$_POST['linkman'];
						$_POST['tel'] =empty($_POST['tel'])? '未填写':$_POST['tel'];
						$_POST['moblie'] =empty($_POST['moblie'])? '未填写':$_POST['moblie'];
						$_POST['cont'] =empty($_POST['cont'])? '未填写':$_POST['cont'];
						
						
						
					$this -> data[$fistcol][$secondcol][] = $_POST;
						data_to_file($this -> data, './data.php');
						$this->success('添加成功', './index.php');
			}
		}
	}
	
	

			

		include './tpl/post.html';
	}
//注册
	public function reg(){
		if(IS_POST){
			$this->dbs[] = array(
				'user' => $_POST['user'],
				'password' => md5($_POST['password'])
			);
			data_to_file($this->dbs, $this->path);
			
			$user = $_POST['user'];
			$password = md5($_POST['password']);
			
			foreach($this->dbs as $v){
				
				if($user == $v['user'] && $password == $v['password']){
				$_SESSION['user'] = $v['user'];
				if(isset($_POST['keep'])){
						setcookie(session_name(),session_id(),time() + 3600 * 24 * 7, '/');
					}else{
						setcookie(session_name(),session_id(),0,'/');
					}
				$this->success('注册成功','./index.php');	
				}
				
			}
		}
		include './tpl/reg.html';
	}
	//登录
	public function login(){
		if(IS_POST){
			$user = $_POST['user'];
			$password = md5($_POST['password']);
			foreach($this->dbs as $v){
				if($user == $v['user'] && $password == $v['password']){
					$_SESSION['user'] =$v['user'];
					if(isset($_POST['keep'])){
						setcookie(session_name(),session_id(),time() + 3600 * 24 * 7, '/');	
					}else{
						setcookie(session_name(),session_id(),0,'/');
					}
				$this->success('登录成功','./index.php');
				
				}
				
			}
			$this->error('用户或密码错误');
		}
		include './tpl/login.html';
	}
	public function out(){
		session_unset();
		session_destroy();
		$this->success('注销成功','./index.php');
	}
	
	
	

}
?>